package com.starblink.android.common.route

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.PretreatmentService
import com.starblink.android.basic.extension.extraOf
import com.starblink.android.basic.urllink.UriLinkConfig
import com.starblink.android.basic.urllink.UriLinkConfig.isHttpLink
import com.starblink.basic.route.RoutePage

/**
 *  Create by yuanl at 2023/4/25
 **/
@Route(path = "/common/pretreatment")
class SkPretreatmentService : PretreatmentService {
    override fun init(context: Context?) {

    }

    override fun onPretreatment(context: Context?, postcard: Postcard?): Boolean {
        val uriStr = postcard?.uri?.toString() ?: postcard?.path
        if (uriStr?.isHttpLink() == true) {
            postcard?.path = RoutePage.Web.PAGE_GLOBAL_H5
            postcard?.group = RoutePage.Web.GROUP.replace("/", "")
            postcard?.uri = null
            postcard?.extraOf(
                RoutePage.Web.ARG_URL to uriStr,
            )
        }
        return true
    }
}